import com.rabbitmq.client.*;
import com.test.sdk.pay.util.ConnectionUtil;

import java.io.IOException;

/**
 * @author 徒有琴
 */
public class SimpleReceive {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        System.out.println(connection);
        Channel channel = connection.createChannel();
        channel.queueDeclare("test_queue", false, false, false, null);
        Consumer consumer = new DefaultConsumer(channel) {
            //钩子方法
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("接收到消息==" + new String(body, "utf-8"));
            }
        };
        channel.basicConsume("test_queue", true, consumer);
    }
}
